
var option;
var myChart_w
//当前选择 周 或者 月
// var choiceWaveDate;
//防止刷新
// let waveDate = window.sessionStorage.getItem("waveDate");
// if (waveDate == "周") {
//   choiceWaveDate = 0;
//   $("#wave_content").text("周");
// } else if (waveDate == "月") {
//   choiceWaveDate = 1;
//   $("#wave_content").text("月");
// } else {
//   choiceWaveDate = 0;
// }
//请求
function getwave(time) {
    if(!time){
    time = []
}
  $.ajax({
    url: baseUrl + "/trend",
    type: "POST",
    dataType: "json",
    // data: {
    //   type: choiceWaveDate, //1本月 0本周
    // },
    success: function (data) {
      // console.log(data.data,'ddd');
      waveData(data.data);
    },
    // 超时时间
    timeout: 4000,
    // 失败的回调
    error: function () {
      // alert("设备故障情况请求数据失败！");
    },
  });
}
//获取数据
function waveData(res) {
  let wave_x = res.map((item) => {
    //x轴
    return item.date
  });
  let x = res.map((item) => {
    //x轴
    return item.num1
  });
  let y = res.map((item) => {
    //x轴
    return item.num2
  });
  waveEcharts(wave_x,x,y);
}

//echarts 数据渲染
function waveEcharts(wave_x,x,y) {
  option = {
    tooltip: {
        trigger: 'axis',
        
        axisPointer: {
            lineStyle: {
                color: '#ddd'
            }
        },
        backgroundColor: 'rgba(255,255,255,1)',
        padding: [5, 10],
        textStyle: {
            color: '#7588E4',
        },
        extraCssText: 'box-shadow: 0 0 5px rgba(0,0,0,0.3)'
    },
    legend: {
        right:'5%',
        orient: 'horizontal',
        data: ['昨日','今日'],
        textStyle:{//图例文字的样式
          color:'#3c9bc4',
          fontSize:14
      }
    },
    xAxis: {
        type: 'category',
        data: wave_x,
        boundaryGap: false,
        splitLine: {
            show: false,
            interval: 'auto',
            lineStyle: {
                color: ['#D4DFF5']
            }
        },
        axisTick: {
            show: false
        },
        axisLine: {
            lineStyle: {
                color: '#609ee9'
            }
        },
        axisLabel: {
            margin: 10,
            textStyle: {
                fontSize: 14
            }
        }
    },
    yAxis: {
        type: 'value',
        splitLine: {
          show:false,
          lineStyle: {
              color: ['#D4DFF5']
          }
        },
        axisLine: {
          show:true,
            lineStyle: {
                color: '#609ee9'
            }
        },
        axisLabel: {
            margin: 10,
            textStyle: {
                fontSize: 14
            }
        }
    },
    series: [{
        name: '今日',
        type: 'line',
        smooth: true,
        showSymbol: false,
        symbol: 'circle',
        symbolSize: 6,
        data: x,
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(199, 237, 250,0.3)'
                }, {
                    offset: 1,
                    color: 'rgba(199, 237, 250,0.1)'
                }], false)
            }
        },
        itemStyle: {
            normal: {
                color: '#f7b851'
            }
        },
        lineStyle: {
            normal: {
                width: 3
            }
        }
    }, {
        name: '昨日',
        type: 'line',
        smooth: true,
        showSymbol: false,
        symbol: 'circle',
        symbolSize: 6,
        data: y,
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(216, 244, 247,0.3)'
                }, {
                    offset: 1,
                    color: 'rgba(216, 244, 247,0.1)'
                }], false)
            }
        },
        itemStyle: {
            normal: {
                color: '#58c8da'
            }
        },
        lineStyle: {
            normal: {
                width: 3
            }
        }
    }]
};
var chartDom_w = document.getElementById("wave");
myChart_w = echarts.init(chartDom_w);
  myChart_w.setOption(option);
  
   window.addEventListener("resize", function() {
    myChart_w.resize();
    });
}


// window.addEventListener("resize", function () {
//   myChart_w.resize();
// });
